/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Test.java
 *
 * Created on Oct 23, 2009, 9:21:13 AM
 */
package CoalitionCirclePackage;

import java.awt.Dimension;
import java.util.List;
import java.util.Vector;

/**
 *
 * @author Heather
 */
public class Test extends javax.swing.JApplet
{

  /** Initializes the applet Test */
  public void init()
  {
    try
    {
      java.awt.EventQueue.invokeAndWait(new Runnable()
      {

        public void run()
        {
          initComponents();
          v.setSize(vSize);
          v.setPreferredSize(vSize);
          container.add(v);
        }
      });
    } catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }

  /** This method is called from within the init() method to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    container = new javax.swing.JPanel();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jButton3 = new javax.swing.JButton();
    jButton4 = new javax.swing.JButton();

    container.setBackground(new java.awt.Color(255, 204, 204));
    container.setLayout(null);

    jButton1.setText("animate");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });
    container.add(jButton1);
    jButton1.setBounds(500, 10, 240, 150);

    jButton2.setText("Randomize Coalition");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });
    container.add(jButton2);
    jButton2.setBounds(500, 160, 240, 140);

    jButton3.setText("Set as root");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton3ActionPerformed(evt);
      }
    });
    container.add(jButton3);
    jButton3.setBounds(500, 300, 240, 100);

    jButton4.setText("animate");
    jButton4.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton4ActionPerformed(evt);
      }
    });
    container.add(jButton4);
    jButton4.setBounds(500, 400, 240, 90);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(container, javax.swing.GroupLayout.DEFAULT_SIZE, 886, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(container, javax.swing.GroupLayout.DEFAULT_SIZE, 580, Short.MAX_VALUE)
    );
  }// </editor-fold>//GEN-END:initComponents

  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
  {//GEN-HEADEREND:event_jButton1ActionPerformed
    // TODO add your handling code here:
    v.createTestAnimation2();
    v.setupCoalitionFormationAnimation(v.createTestAnimation());

    v.startAnimation();
  }//GEN-LAST:event_jButton1ActionPerformed

  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
  {//GEN-HEADEREND:event_jButton2ActionPerformed
    // TODO add your handling code here:
    if (root != null)
    {
      List<List<int[]>> newCoalition = v.generateRandomCoalition();
      v.setCoalitions(root);
      repaint();
      
      v.clearAnimationScript();
      v.setupCoalitionFormationAnimationWithInitialPause(newCoalition);
      v.startAnimation();
    }
    else
    {
      v.setRandomCoalition();
    }
  }//GEN-LAST:event_jButton2ActionPerformed

  private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton3ActionPerformed
  {//GEN-HEADEREND:event_jButton3ActionPerformed
    // TODO add your handling code here:
    List<List<int[]>> rootClone = new Vector<List<int[]>>();
    for (List<int[]> coalition : v.getCoalitions())
    {
      Vector<int[]> cloneCoalition = new Vector<int[]>();

      for (int[] group : coalition)
      {
        int[] cloneI = new int[group.length];

        for (int i = 0; i < cloneI.length; i++)
        {
          cloneI[i] = group[i];
        }

        cloneCoalition.add(cloneI);
      }

      rootClone.add(cloneCoalition);
    }

    root = rootClone;
  }//GEN-LAST:event_jButton3ActionPerformed

  private void jButton4ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton4ActionPerformed
  {//GEN-HEADEREND:event_jButton4ActionPerformed
    // TODO add your handling code here:
  }//GEN-LAST:event_jButton4ActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JPanel container;
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JButton jButton3;
  private javax.swing.JButton jButton4;
  // End of variables declaration//GEN-END:variables
  CoalitionCircleViewer v = new CoalitionCircleViewer();
  Dimension vSize = new Dimension(500, 500);
  List<List<int[]>> root = null;
}
